package ace.module.captcha.core.impl.controller.graphql.open;

import ace.module.captcha.core.impl.controller.graphql.constant.GraphqlSchemaConstants;
import ace.module.captcha.core.impl.controller.graphql.model.dto.CaptchaItemBase64DataImageDto;
import ace.module.captcha.core.impl.service.CaptchaImageService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author caspar
 * @date 2023/9/23 9:56
 */
@AllArgsConstructor
@Slf4j
@RestController
public class CaptchaItemOpenController {
  private final CaptchaImageService captchaImageService;

  /**
   * 获取图形验证码
   * data是base 64 图片数据.example: 
   */
  @QueryMapping(GraphqlSchemaConstants.Query.captchaItemOpenGetBase64Image)
  public CaptchaItemBase64DataImageDto captchaItemPublicGetBase64Image(
      @Valid @NotNull @Argument("captchaAppId") Long captchaAppId) {
    CaptchaItemBase64DataImageDto result = captchaImageService.createBase64WithItem(captchaAppId);
    return result;
  }
}
